import hashlib
from django.conf import settings


def md5(data_string):
    '''
    md5加密
    :param data_string:
    :return:
    '''
    # 创建md5对象并加盐，参数是django自带的随机字符串
    obj = hashlib.md5(settings.SECRET_KEY.encode('utf-8'))

    # 此处必须声明encode
    obj.update(data_string.encode('utf-8'))
    return obj.hexdigest()
